package com.lemon.smartsafety.ui.adapter.safe.inspection;

import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.CardView;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.ldzs.recyclerlibrary.view.SpacesItemDecoration;
import com.lemon.smartsafety.R;
import com.lemon.smartsafety.app.IApplication;
import com.lemon.smartsafety.entity.common.EvidenceDataI;
import com.lemon.smartsafety.entity.safe.inspection.FireCheckLastDetailVo;
import com.lemon.smartsafety.ui.activity.fire.FirefightingUtil;
import com.lemon.smartsafety.ui.adapter.common.HorizontalEvidenceAdapter;
import com.lemon.smartsafety.utils.LogUtils;
import com.lemon.smartsafety.utils.common.DateUtils;
import com.lemon.smartsafety.utils.common.StringUtils;

import java.util.ArrayList;
import java.util.List;

import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * Created by Cooliean on 16/3/29.
 */
public class CheckItemRecordAdapter extends LemonRcvAdapter<FireCheckLastDetailVo> {
    public CheckItemRecordAdapter(@Nullable List<FireCheckLastDetailVo> data) {
        super(data);
    }

    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new CheckItemRecordItem();
    }

    public class CheckItemRecordItem implements AdapterItem<FireCheckLastDetailVo> {

        CardView        mainCardView;
        TextView        tvCheckTime;
        ImageView ivStatusLight;
        TextView        tvCheckRemark;
        RecyclerView    recyclerView;


        SpacesItemDecoration mItemDecoration;

        private FireCheckLastDetailVo mData;
        private int                   mPosition;

        Drawable statusLightSrc = null;

        @Override
        public int getLayoutResId() {
            return R.layout.item_check_item_record;
        }

        @Override
        public void bindViews(View root) {
            mainCardView = (CardView) root.findViewById(R.id.main_card_view);
            tvCheckTime = (TextView) root.findViewById(R.id.tv_check_time);
            ivStatusLight = (ImageView) root.findViewById(R.id.iv_status_light);
            statusLightSrc = ivStatusLight.getDrawable();
            tvCheckRemark = (TextView) root.findViewById(R.id.tv_check_remark);
            recyclerView = (RecyclerView) root.findViewById(R.id.recyclerView);

            int spacingInPixels = recyclerView.getContext().getResources().getDimensionPixelSize(R.dimen.item_grid_divider_line);
            mItemDecoration = new SpacesItemDecoration(spacingInPixels);
            recyclerView.addItemDecoration(mItemDecoration);
        }

        @Override
        public void setViews() {
        }

        @Override
        public void handleData(FireCheckLastDetailVo data, int position) {
            mData = data;
            mPosition = position;

            tvCheckTime.setText(DateUtils.getFormatDateStringWithDateString(StringUtils.nullValue(data.getLastCheckDate()), DateUtils.dateFormatYMDHMS));


            String statusString = StringUtils.nullValue(data.getStatus(), "0");
      /*      if (DataInfo.RED_TAG.equals(statusString)) {
                ivStatusLight.setImageDrawable(DrawableUtils.$tint(statusLightSrc, ivStatusLight.getContext().getResources().getColor(R.color.colorAppRed)));
            } else if (DataInfo.YELLOW_TAG.equals(statusString)) {
                ivStatusLight.setImageDrawable(DrawableUtils.$tint(statusLightSrc, ivStatusLight.getContext().getResources().getColor(R.color.colorAppYellow)));
            } else {
                ivStatusLight.setImageDrawable(DrawableUtils.$tint(statusLightSrc, ivStatusLight.getContext().getResources().getColor(R.color.colorAppGreen)));
            }*/

            LogUtils.LOGE("颜色状态："+statusString);
            ivStatusLight.setBackgroundResource(FirefightingUtil.getScoreImgCircleColor(statusString));

            tvCheckRemark.setText(StringUtils.nullValue(data.getRemark(), "无").trim());




            List<EvidenceDataI> result = new ArrayList<>();
            result.addAll(data.getAssetsList());
            if (result.size() != 0) {
                /**
                 * 证据视图部分
                 */
                HorizontalEvidenceAdapter evidenceAdapter = new HorizontalEvidenceAdapter(result);
                LinearLayoutManager       layoutManager   = new LinearLayoutManager(IApplication.context(), LinearLayoutManager.HORIZONTAL, false);
                recyclerView.setLayoutManager(layoutManager);
                recyclerView.setAdapter(evidenceAdapter);
            }

        }
    }
}
